import {ITimerAdapter} from "../../adapterInterface/model2/ITimerAdapter";
import {Logger} from "../../../config/Logger";


export class TimerAdapter implements ITimerAdapter {
  createHandle() {
    return CreateTimer();
  }
  destroy(timer: any, dialog: any) {
    handle_unref(timer);
    DestroyTimer(timer);
    if (dialog) {
      handle_unref(dialog);
      DestroyTimerDialog(dialog);
    }
  }
  pause(handle: any) {
    PauseTimer(handle);
  }
  resume(handle: any) {
    ResumeTimer(handle);
  }
  start(handle: any, timeout: number, periodic: boolean, handlerFunc: (this: void) => void) {
    TimerStart(handle, timeout, periodic, handlerFunc);
  }

  showDialog(handle: any, text: string) {
    const dialog = CreateTimerDialog(handle);
    handle_ref(dialog);
    TimerDialogSetTitle(dialog, text);
    TimerDialogDisplay(dialog, true);
    return dialog;
  }

  bindHandle(handle: any): void {
    handle_ref(handle);
  }
  equal(handle1: any, handle2: any): boolean {
    return (GetHandleId(handle1) === GetHandleId(handle2))
  }

  getRemaining(handle: any): number {
    return TimerGetRemaining(handle);
  }

  isValid(handle: any): boolean {
    if (handle) {
      return true;
    }
    return false;
  }
}
